package com.repository.impl;

import com.entity.*;
import com.repository.PatientRepository;
import com.utils.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.Vector;

public class PatientRepositoryImpl implements PatientRepository {
    @Override
    public int addRegisterDoc(RegisterDoc registerDoc) {
        SqlSession sqlSession= MybatisUtil.getSqlSession();
        PatientRepository patientRepository=sqlSession.getMapper(PatientRepository.class);
        int rs=patientRepository.addRegisterDoc(registerDoc);
        sqlSession.commit();
        sqlSession.close();
        return rs;
    }

    @Override
    public Vector<Drug> findThisDrugs(String account) {
        SqlSession sqlSession= MybatisUtil.getSqlSession();
        PatientRepository patientRepository=sqlSession.getMapper(PatientRepository.class);
        Vector<Drug> drugs=patientRepository.findThisDrugs(account);
        sqlSession.close();
        return drugs;
    }

    @Override
    public Vector<Diagnose> findThisDiagnoses(String account) {
        SqlSession sqlSession= MybatisUtil.getSqlSession();
        PatientRepository patientRepository=sqlSession.getMapper(PatientRepository.class);
        Vector<Diagnose> diagnoses=patientRepository.findThisDiagnoses(account);
        sqlSession.close();
        return diagnoses;
    }

    @Override
    public Vector<Cost> findThisCosts(String account) {
        SqlSession sqlSession= MybatisUtil.getSqlSession();
        PatientRepository patientRepository=sqlSession.getMapper(PatientRepository.class);
        Vector<Cost> costs=patientRepository.findThisCosts(account);
        sqlSession.close();
        return costs;
    }

    @Override
    public int isExistPatientByAccount(String account) {
        SqlSession sqlSession= MybatisUtil.getSqlSession();
        PatientRepository patientRepository=sqlSession.getMapper(PatientRepository.class);
        int rs=patientRepository.isExistPatientByAccount(account);
        sqlSession.close();
        return rs;
    }

    @Override
    public int addPatientLogin(Patient patient) {
        SqlSession sqlSession=MybatisUtil.getSqlSession();
        PatientRepository patientRepository=sqlSession.getMapper(PatientRepository.class);
        int rs=patientRepository.addPatientLogin(patient);
        sqlSession.commit();
        sqlSession.close();
        return rs;
    }

    @Override
    public Patient patientInfoFindByAccount(String account) {
        SqlSession sqlSession=MybatisUtil.getSqlSession();
        PatientRepository patientRepository=sqlSession.getMapper(PatientRepository.class);
        Patient patient= patientRepository.patientInfoFindByAccount(account);
        sqlSession.close();
        return patient;
    }

    @Override
    public int isPatientLogin(Patient patient) {
        SqlSession sqlSession=MybatisUtil.getSqlSession();
        PatientRepository patientRepository=sqlSession.getMapper(PatientRepository.class);
        int rs=patientRepository.isPatientLogin(patient);
        sqlSession.close();
        return rs;
    }

    @Override
    public int updatePatient(Patient patient) {
        SqlSession sqlSession=MybatisUtil.getSqlSession();
        PatientRepository patientRepository=sqlSession.getMapper(PatientRepository.class);
        int rs=patientRepository.updatePatient(patient);
        sqlSession.commit();
        sqlSession.close();
        return rs;
    }

    @Override
    public RegisterDoc findRegisterDoc(String registerId) {
        SqlSession sqlSession=MybatisUtil.getSqlSession();
        PatientRepository patientRepository=sqlSession.getMapper(PatientRepository.class);
        RegisterDoc registerDoc=patientRepository.findRegisterDoc(registerId);
        sqlSession.close();
        return registerDoc;
    }

    @Override
    public Vector<RegisterDoc> findAllThisRegisterDocs(String account) {
        SqlSession sqlSession=MybatisUtil.getSqlSession();
        PatientRepository patientRepository=sqlSession.getMapper(PatientRepository.class);
        Vector<RegisterDoc> registerDocs=patientRepository.findAllThisRegisterDocs(account);
        sqlSession.close();
        return registerDocs;
    }
}
